var gulp = require('gulp');
var gulp_minify_css=require("gulp-minify-css");
var gulp_sass=require("gulp-sass");
var gulp_uglify=require("gulp-uglify");
var babel = require('gulp-babel');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync').create();//浏览器热更新
//定义自动刷新浏览器任务
gulp.task("bs",function(){
	browserSync.init({
		server:{
			baseDir:"./"
		},
		//修改端口号
		port:4000
	})
	gulp.watch("src/scss/**/*.scss" ,["sass"])
		.on("change",browserSync.reload)
});

gulp.task("init",function(){
	console.log("init")
})

gulp.task("minifycss",function(){
	//文件源头
	gulp.src("src/css/**/*.css")
	     .pipe(gulp_minify_css())
	     .pipe(gulp.dest("dist/css"))
})

gulp.task("sass",function(){
	gulp.src("src/scss/*.scss")
	     .pipe(gulp_sass())
	     .pipe(gulp.dest("dist/scss"))
})

gulp.task("watchscss",function(){
	gulp.watch("src/scss/**/*.scss",["sass"])
		.on("change",function(e){
			console.log(e)
		})
})

gulp.task("minifyjs",function(){
//	文件源头 
	gulp.src("src/js/**/*.js") //*号代表所有
		.pipe(babel({
				presets:['env']
		}))
		.pipe(gulp_uglify())
		.pipe(gulp.dest("dist/js"));
})

gulp.task("copyHtml",function(){
	gulp.src("src/**/*.html")
		.pipe(gulp.dest("dist/"))	
})

gulp.task("copyHtml",function(){
	gulp.src("src/**/*.html")
		.pipe(gulp.dest("dist/"))	
})

gulp.task('testImagemin', function () {
    gulp.src('src/img/*.{png,jpg,gif,ico}')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/img'));
});

//一键压缩css,js,HTML
gulp.task("pro",["copyHtml","minifycss","minifyjs","testImagemin"])
